






package com.yunxiangyue.User_room

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.yunxiangyue.User


//这个数据库的版本号不能再修改了注意

@Database(version = 1, entities = [User::class])
abstract class UserDatabase: RoomDatabase() {

    abstract fun userDao():UserDao


    companion object{
        private var instance:UserDatabase? = null

        @Synchronized
        fun getUserDatabase(context: Context):UserDatabase{
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext, UserDatabase::class.java,"user_databse").allowMainThreadQueries()
//                .addMigrations(Migration1To2())
//                .fallbackToDestructiveMigration()
                .build().apply {
                    instance = this
                }
        }
    }
}
//class Migration1To2 : Migration(1,3) {
//    override fun migrate(database: SupportSQLiteDatabase) {
//
//        database.execSQL("alter table User add column location text")
//        database.execSQL("DROP TABLE IF EXISTS MusicListItem");
//    }
//}